package cc.iotkit.data.dao;

import cc.iotkit.data.model.TbWzrGwDev;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


public interface WzrGwDevRepository extends JpaRepository<TbWzrGwDev, Long> {
    /**
     * 根据网关编号查询网关最近的pvid
     * @param gwName
     * @return
     */
    @Query(value = "SELECT * FROM wzr_gw_dev  where gw_name = :gwName order by create_time desc limit 1",nativeQuery = true)
    TbWzrGwDev findBygwName(@Param("gwName") String gwName);

    /**
     * 查询当前设备是否已被添加到网关
     * @param deviceId
     */
    @Query(countQuery = "SELECT * FROM wzr_gw_dev where device_id = :deviceId",nativeQuery = true)
    TbWzrGwDev findBydeviceId(@Param("deviceId") String deviceId);

    void deleteTbWzrGwDevByDeviceId(String deviceId);

    @Query(value = "select * from wzr_gw_dev ",nativeQuery = true)
    Page<TbWzrGwDev> findAllByPag(Pageable pageable);
}